package com.bai.localshop.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 布隆过滤器配置
 */
@Configuration
public class RBloomFilterConfiguration {

    /**
     * 防缓存穿透布隆过滤器
     */
    @Bean
    public RBloomFilter<String> createCachePenetrationBloomFilter(RedissonClient redissonClient) {
        RBloomFilter<String> cachePenetrationBloomFilter =
                redissonClient.getBloomFilter("product_cache_penetration_bloom_filter");
        cachePenetrationBloomFilter.tryInit(10000L, 0.03);  // 1万商品，3%误判率
        return cachePenetrationBloomFilter;
    }
}